package com.example.demoapp.controller;

import com.example.demoapp.entity.Employee;
import com.example.demoapp.exception.BusinessException;
import com.example.demoapp.pojo.Result;
import com.example.demoapp.service.EmployeeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;


//说明这是对外提供接口的一个类@RestController
@RestController
public class hghController {

    //引入service业务层资源
    @Resource
    EmployeeService employeeService;

    //标注他是一个get请求路径为 /hgh    @GetMapping("/hgh")
    @GetMapping("/hgh")
    public Result<Object> hgh() {
        HashMap<Object,Object> map = new HashMap<>();
        map.put("name","帅比");
        map.put("age",18);
        return Result.success(map,"自定义的六百六十六返回信息");
    }

    //登入接口
    @PostMapping("/login")
    public Result<Object> login(@RequestBody Employee  employee) {
        //将账号密码提交给service层（处理逻辑）
        Employee resultEmployee =  employeeService.login(employee);
        return Result.success(resultEmployee,"登入成功");
    }

    //注册接口
    @PostMapping("/register")
    public Result<Object> register(@RequestBody Employee  employee) {
        //将账号密码提交给service层（处理逻辑）
        int result =  employeeService.register(employee);
        return Result.success(null,result>0?"注册成功":"注册失败");
    }

}
